package com.huilian.iotbox.data.cmd;

import com.huilian.iotbox.data.constants.IotConstant;
import com.huilian.iotbox.data.utils.IotBoxUtil;

/**
 * @author 谢洛涛
 * @date 2023/10/12 17:30
 */
public class VendmachResponseDataFrameCMD {


    // 电机测试回复给控制板
    public static String shipmentReport(String deviceNo,String orderNo,String mcd,String command) {
        StringBuilder stringBuilder = new StringBuilder(IotConstant.CONTENT_PREFIX);
        // 帧长度
        StringBuilder dataPrefix = new StringBuilder("01C9").append(command);
        dataPrefix.append(IotBoxUtil.singleString2Hex(deviceNo)).append(mcd);
        dataPrefix.append(IotBoxUtil.convertStringToHex(orderNo));
        Integer lengthStr = (dataPrefix.length()/2)+1;
        dataPrefix.insert(0, IotBoxUtil.singleInt2Hex(lengthStr));
        stringBuilder
                .append(dataPrefix)
                .append(IotBoxUtil.checkcode_0007(dataPrefix.toString()))
                .append(IotConstant.CONTENT_SUFFIX);
        return stringBuilder.toString().toUpperCase();
    }

    // 格子机回复
    public static String LatticeShipmentReport(String content,String orderNo,String mcd,Integer doorNumber,Integer stats) {
        StringBuilder stringBuilder = new StringBuilder(IotConstant.CONTENT_PREFIX);
        // 帧长度
        StringBuilder dataPrefix = new StringBuilder("01C90F");
        dataPrefix.append(IotBoxUtil.convertStringToHex(orderNo)).append(content).append(mcd)
                .append(IotBoxUtil.singleInt2Hex(doorNumber)).append(stats);

        Integer lengthStr = (dataPrefix.length()/2)+1;
        dataPrefix.insert(0, IotBoxUtil.singleInt2Hex(lengthStr));
        stringBuilder
                .append(dataPrefix)
                .append(IotBoxUtil.checkcode_0007(dataPrefix.toString()))
                .append(IotConstant.CONTENT_SUFFIX);
        return stringBuilder.toString().toUpperCase();
    }
}
